package com.zhonghui.controller;

import com.zhonghui.common.core.result.FwResult;
import com.zhonghui.dto.AccountLoginDto;
import com.zhonghui.model.Admin;
import com.zhonghui.service.AdminService;
import com.zhonghui.dto.PhoneLoginDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;


@RestController
@Api(value = "管理员接口")
@Slf4j
@Validated
@RequestMapping("admin")
public class AdminController {


    @Autowired
    private AdminService adminService;


    @ApiOperation("账号登录")
    @PostMapping("/login")
    public FwResult<Map<String,Object>> login(@RequestBody @Valid AccountLoginDto accountLoginDto){
        log.info("账号登录{}",accountLoginDto.getAccount());
        return adminService.login(accountLoginDto);
    }

    @ApiOperation("登出")
    @PostMapping("/logout")
    public FwResult<Admin> logout(@RequestHeader(value = "Authorization",required = false) String token){
        return adminService.logout(token);
    }


}
